﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Data.Entity;
using ZX.OA.Model;

namespace ZX.OA.DAL
{
    public class ProjectInfoDal
    {
        Entity entity = new Entity();
        /// <summary>
        /// 项目的信息显示
        /// </summary>
        /// <returns></returns>
        public List<ProjectInfo> GetProject()
        {
            return entity.ProjectInfo.ToList();
        }
        /// <summary>
        /// 项目的类型信息显示
        /// </summary>
        /// <returns></returns>
        public List<ProjectTypeInfo> Drop_ProjectType()
        {
            return entity.ProjectTypeInfo.ToList();
        }
        /// <summary>
        /// 项目状态的信息显示
        /// </summary>
        /// <returns></returns>
        public List<ProjectStateInfo> Drop_ProjectState()
        {
            return entity.ProjectStateInfo.ToList();
        }
        /// <summary>
        /// 添加项目
        /// </summary>
        /// <param name="t"></param>
        /// <returns></returns>
        public int ProjectInfoAdd(ProjectInfo t)
        {
            entity.ProjectInfo.Add(t);
            return entity.SaveChanges();
        }
        /// <summary>
        /// 项目删除
        /// </summary>
        /// <param name="id"></param>
        /// <returns></returns>
        public int DeleProject(int id)
        {
            entity.ProjectInfo.Remove(entity.ProjectInfo.Find(id));
            return entity.SaveChanges();
        }
        /// <summary>
        /// 根据项目编号获取办公用品信息
        /// </summary>
        /// <param name="id"></param>
        /// <returns></returns>
        public ProjectInfo GetProjectId(int id)
        {
            return entity.ProjectInfo.Find(id);
        }
        /// <summary>
        /// 修改办公用品信息
        /// </summary>
        /// <param name="s"></param>
        /// <returns></returns>
        public int ProjectUpdate(StationeryInfo s)
        {
            entity.Entry(s).State = System.Data.EntityState.Modified;
            return entity.SaveChanges();
        }
        /// <summary>
        /// 根据项目编号或项目名称查询项目信息
        /// </summary>
        /// <param name="ProjectName"></param>
        /// <param name="ProjectId"></param>
        /// <returns></returns>
        public List<ProjectInfo> SrachProject(string ProjectName,int ? ProjectId)
        {
            return entity.ProjectInfo.Where((p => (string.IsNullOrEmpty(ProjectName) ? true : p.ProjectName.Contains(ProjectName)) || (p.ProjectId == null ? true : p.ProjectId == ProjectId))).ToList();
        }
        
    }
}
